<?php
	require_once("conn.php");
	require_once("smarty/Smarty.class.php");

	//about types
	session_start();
	if(isset($_POST['radiobutton'])){
		$_SESSION['flag'] = $_POST['radiobutton'];
	}
	if(!(isset($_GET['type_id']))){
		$type_id_within_web = 1;
	}
	else{
		$type_id_within_web = $_GET['type_id'];
	}
	$article_num = 0;
	$type_id_within_array = $type_id_within_web-1;

	mysql_select_db($dataname,$conn);
	$query_rs_types = "select * from types order by type_id ASC";
	mysql_query("set names 'gbk'");
	$rs_types = mysql_query($query_rs_types,$conn) or die(mysql_error());
	$array_rs_types = array();
	$array_rs_type_name = array();
	$array_rs_type_id = array();

	while($row_rs_types = mysql_fetch_assoc($rs_types)){
		array_push($array_rs_types,$row_rs_types);
		array_push($array_rs_type_name,$row_rs_types['type_name']);
		array_push($array_rs_type_id,$row_rs_types['type_id']);
	}

    //about artilces

    mysql_select_db($dataname,$conn);
    $query_rs_articles = "select * from articles order by last_update_time DESC";
    $query_rs_articles_limit = "select * from articles limit 0,10 order by last_update_time DESC";
    mysql_query("set names 'gbk'");
    $rs_articles = mysql_query($query_rs_articles,$conn) or die(mysql_error());
    $array_rs_articles = array();
    $array_rs_article_id = array();
    $array_rs_articles_limit = array();
    $array_rs_articles_random = array();
    $array_rs_articles_random_limit = array();

    while($row_rs_articles = mysql_fetch_assoc($rs_articles)){
		array_push($array_rs_articles,$row_rs_articles);
		array_push($array_rs_article_id,$row_rs_articles['article_id']);
	}

	$array_rs_articles_random = array_slice($array_rs_articles,0);
    	shuffle($array_rs_articles_random);
	$array_rs_articles_random_limit = array_slice($array_rs_articles_random,0,10);
	$array_rs_articles_limit = array_slice($array_rs_articles,0,10);


   //about config

	$query_rs_config = "select * from config";
    	$rs_config = mysql_query($query_rs_config,$conn) or die(mysql_error());
	$row_rs_config = mysql_fetch_assoc($rs_config);
	$row_rs_config_copyright = $row_rs_config['copyright'];



   //about smarty

	$smarty = new Smarty;
    $smarty->left_delimiter = '[{';
	$smarty->right_delimiter = '}]';

	$smarty->assign("array_rs_types",$array_rs_types);
	$smarty->assign("array_rs_type_name",$array_rs_type_name);
	$smarty->assign("array_rs_type_id",$array_rs_type_id);
	$smarty->assign("array_rs_articles",$array_rs_articles);
	$smarty->assign("array_rs_articles_limit",$array_rs_articles_limit);
	$smarty->assign("array_rs_articles_random_limit",$array_rs_articles_random_limit);
	$smarty->assign("row_rs_config_copyright",$row_rs_config_copyright);
	$smarty->assign("type_id_within_web",$type_id_within_web);
	$smarty->assign("type_id_within_array",$type_id_within_array);
	$smarty->assign("article_num",$article_num);
	$smarty->display('list'.$_SESSION['flag'].'.tpl');

?>